package com.cqut.hfh.ordering.controller;

import com.cqut.hfh.ordering.service.IFodDetailService;
import com.cqut.hfh.ordering.utils.Message;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * @author LJH
 * @date 2019/6/25-21:47
 */
@RequestMapping("/fodDetail")
@Controller
public class FodDetailController {

    @Resource
    private IFodDetailService fodDetailService;


    /**
     * 返回所有订单食物详情
     * @return
     */
    @RequestMapping(path = "/findAll", produces = {"text/html;charset=utf-8"})
    @ResponseBody
    public String findAll(@RequestParam("limit") String limit,
                          @RequestParam("page") String page,
                          @RequestParam("indentId")String indent_id){
        List<Map<String, Object>> result_list = fodDetailService.getDetails(limit, page, indent_id);

        for( Map<String, Object> map : result_list){
            if( map.get("isva").toString().equals("1")){
                map.put("isva", "有效");
            }
            if( map.get("isva").toString().equals("0")){
                map.put("isva", "无效");
            }
            DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String tsStr = sdf.format(map.get("optime"));
            map.put("optime", tsStr);
        }

        Integer count = fodDetailService.getCount();

        return Message.getReturnMsg(0,"", count, result_list);
    }

}
